<template>
	<page-meta><navigation-bar title="好友请求..." front-color="#000000" background-color="#ffffff" /></page-meta>
	<view class="content">
		<view class="item" v-for="(item, index) in ynumlist" @longtap="show=true;nowtap=index" :key="item.userId + 1"  hover-class="message-hover-class">
			<image mode="aspectFill" :src="item.headImg" />
			<!-- 此层wrap在此为必写的，否则可能会出现标题定位错误 -->
			<view class="right u-border-bottom title-wrap">
				<view class="right_top">
					<view class="right_top_name u-line-1">{{ item.userName }}(好友请求)</view>
					<view class="right_top_time ">{{ item.sendtime }}</view>
				</view>
				<view class="right_btm ">
					<view class="u-line-1" v-if="item.contentType == 1">{{ item.content}}</view>
					<view class=""><u-button size="mini" type="success" style="padding: 0 10px;height: 25px;line-height: 25px; display: block;" v-if="item.num" @tap="jieshou(item)">同意</u-button>
					<u-button size="mini" type="success" style="padding: 0 10px;height: 25px;line-height: 25px; display: block;background:#ccc;" v-else>已同意</u-button></view>
				</view>
			</view>
		</view>
		<text v-if="!ynumlist.length" style="display: block;text-align: center;color: red;padding-top: 100px;">这里空空如也！</text>
		<u-popup v-model="show" mode="center" border-radius="14">
				<view style="padding: 10px;">
					<u-button size="mini" type="success" style="margin: 20px;padding: 0 90px;height: 40px;line-height: 40px; display: block;" @tap="click(nowtap,1)">置顶</u-button>
					<u-button size="mini" type="error" style="margin: 20px;padding: 0 90px;height: 40px;line-height: 40px;display: block;" @tap="click(nowtap,0)">删除</u-button>
				</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				nowtap:{},
				show:false,
				
			}
		},
		methods: {
			click(index, index1) {
				if (index1 == 0) {//删除
					var uid = this.ynumlist[index].userId;
					this.ynumlist.splice(index, 1);
					this.$u.vuex('ynumlist', []);
					this.$u.vuex('ynumlist', this.ynumlist);
				}else{//置顶
					var obj = {};
					for(var i in this.ynumlist[index]){
						obj[i] = this.ynumlist[index][i];
					};
					this.ynumlist.splice(index, 1);
					this.ynumlist.unshift(obj);
					this.$u.vuex('ynumlist', []);
					this.$u.vuex('ynumlist', this.ynumlist);
				};
				this.show = false;
			},
			jieshou(obj){
				var sid = obj.fromUserId;
				var uid = this._user_info.userId;
				uni.request({
					url: this.$store.state.url + '/addflist',
					method: 'POST',
					data: {
						sid,
						uid
					},
					success: res => {
						res = res.data;
						if (res.code == 200) {
							this.$u.vuex('firendList', res.lst);
							obj.num = 0;
							this.$u.vuex('ynumlist', []);
							this.$u.vuex('ynumlist', this.ynumlist);
							uni.sendSocketMessage({
							      data: JSON.stringify({sendid:sid,reset:true})
							});
						} else {
				
						}
					},
					fail: res => {
						uni.showToast({
							title: '服务器错误！',
							icon: 'none'
							// position:'top'
						});
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		.item {
			width: 750rpx;
			display: flex;
			align-items: center;

			// padding: 20rpx;
			image {
				width: 76rpx;
				height: 76rpx;
				margin: 20rpx;
				border-radius: 12rpx;
				flex: 0 0 76rpx;
			}

			.right {
				overflow: hidden;
				flex: 1 0;
				padding: 20rpx 20rpx 20rpx 0;

				&_top {
					display: flex;
					justify-content: space-between;

					&_name {
						font-size: 28rpx;
						color: $u-main-color;
						flex: 0 0 450rpx;
						overflow: hidden;
					}

					&_time {
						font-size: 22rpx;
						color: $u-light-color;
					}
				}

				&_btm {
					display: flex;
					justify-content: space-between;
					align-items: center;
					font-size: 22rpx;
					color: $u-tips-color;
					padding-top: 10rpx;
				}
			}
		}

		.bg_view {
			background-color: #fafafa;
		}

		.slot-wrap {
			display: flex;
			align-items: center;
			padding: 0 30rpx;
		}
	}
</style>
